/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.orderView;
/**
 * 订单管理主窗体
 */
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.commons.util.SwingUtil;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.view.base.BaseInternalFrame;
import com.ruipengkj.view.memberView.OrderManagePanel;

public class OrderInternalFrame extends BaseInternalFrame {

	
	private static final long serialVersionUID = 1L;
	private JToolBar toolBar;//工具栏
	
	private JPanel main;//主面板
	private CardLayout main_layout;//主面板布局
	
	private JButton memberConsumptionButton;//会员消费按钮
	private MemberConsumptionPanel memberConsumptionPanel;//会员消费面板
	
	private JButton orderOnlineButton;//在线订按钮
	private OrderOnlinePanel orderOnlinePanel;//在线订面板
	
	private JButton orderScheduledButton;//在线预订单按钮
	private OrderScheduledPanel orderScheduledPanel;//在线预订单面板
	
	
	private JButton orderCommentsButton;//订单评论按钮
	private AllPanel orderCommentsPanel;//订单评论面板
	
	private JButton marketButton;//销售退货单按钮
	private MarketReturnedPanel marketReturnedPanel;//销售退货单面板
	
	private JButton orderManageButton;//销售退货单按钮
	private OrderManagePanel orderManagePanel;//销售退货单面板
	
	private JButton orderRefundButton;//退款单按钮
	private OrderRefundPanel orderRefundPanel;//退款单版面
	
	public OrderInternalFrame(String title, boolean resizable,
			boolean closable, boolean maximizable, boolean iconifiable) {
		super(title, resizable, closable, maximizable, iconifiable);
		init();
	}
	
	private void init(){
		this.setLayout(new BorderLayout());
		this.initComponents();
		this.initListener();
	}
	
	//初始化组件
	private void initComponents() {
		toolBar = new JToolBar();
		toolBar.setFloatable(false);//设置工具栏不可移动
		memberConsumptionButton=new JButton("销  售",SwingUtil.getOpenSwingImage("member_manager.png"));
		orderOnlineButton = new JButton("在线订单",SwingUtil.getOpenSwingImage("order_online.png"));
		orderScheduledButton = new JButton("在线预订单",SwingUtil.getOpenSwingImage("order_manager.png"));
//		orderHistoryButton=new JButton("历史订单",SwingUtil.getOpenSwingImage("order_history.png"));
		orderCommentsButton = new JButton("订单评论",SwingUtil.getOpenSwingImage("order_comment.png"));
		marketButton=new JButton("销售退货单",SwingUtil.getOpenSwingImage("market_return_single.png"));
		orderManageButton = new JButton("订单处理",SwingUtil.getOpenSwingImage("market_return_single.png"));
		orderRefundButton = new JButton("退款单处理",SwingUtil.getOpenSwingImage("market_return_single.png"));
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL11)){
			toolBar.add(memberConsumptionButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL12)){
			toolBar.add(orderOnlineButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL13)){
			toolBar.add(orderScheduledButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL14)){
			toolBar.add(orderCommentsButton);
		}

		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL15)){
			toolBar.add(marketButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL16)){
			toolBar.add(orderManageButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL17)){
			toolBar.add(orderRefundButton);
		}
		
		main_layout = new CardLayout();
		main = new JPanel(main_layout);
		this.add(toolBar, BorderLayout.NORTH);
		this.add(main, BorderLayout.CENTER);
	}
	
	//初始化监听器
	private void initListener() {
		memberConsumptionButton.addActionListener(this);
		orderCommentsButton.addActionListener(this);
		orderScheduledButton.addActionListener(this);
		orderOnlineButton.addActionListener(this);
		marketButton.addActionListener(this);
		orderManageButton.addActionListener(this);
		orderRefundButton.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==memberConsumptionButton){
			//会员卡消费按钮
			memberConsumptionPanel=new MemberConsumptionPanel();
			main.add(memberConsumptionPanel,"memberConsumptionPanel");
			main_layout.show(main, "memberConsumptionPanel");
			this.setTitle("订单管理--销  售");
			Util.setButtonStatus(toolBar,memberConsumptionButton);
		}else if(e.getSource() == orderOnlineButton) {
			//在线订按钮
			orderOnlinePanel = new OrderOnlinePanel();
			main.add(orderOnlinePanel, "orderOnlinePanel");
			main_layout.show(main, "orderOnlinePanel");
			this.setTitle("订单管理--在线订单");
			Util.setButtonStatus(toolBar,orderOnlineButton);
			SwingUtilities.invokeLater(orderOnlinePanel);
		}else if(e.getSource() == orderScheduledButton) {
			//在线预订单按钮
			orderScheduledPanel = new OrderScheduledPanel();
			main.add(orderScheduledPanel, "orderScheduledPanel");
			main_layout.show(main, "orderScheduledPanel");
			this.setTitle("订单管理--在线预订单");
			Util.setButtonStatus(toolBar,orderScheduledButton);
			SwingUtilities.invokeLater(orderScheduledPanel);
		}else if(e.getSource() == orderCommentsButton) {
			//订单评论
			orderCommentsPanel = new AllPanel();
			main.add(orderCommentsPanel, "orderCommentsPanel");
			main_layout.show(main, "orderCommentsPanel");
			this.setTitle("订单管理--订单评论");
			Util.setButtonStatus(toolBar,orderCommentsButton);
			SwingUtilities.invokeLater(orderCommentsPanel);
		}else if(e.getSource()==marketButton){
			//销售退货单按钮
			marketReturnedPanel = new MarketReturnedPanel();
			main.add(marketReturnedPanel,"marketReturnedPanel");
			main_layout.show(main, "marketReturnedPanel");
			this.setTitle("订单管理--销售退货");
			Util.setButtonStatus(toolBar,marketButton);
			SwingUtilities.invokeLater(marketReturnedPanel);
		}else if(e.getSource()==orderManageButton){
			//销售退货单按钮
			orderManagePanel = new OrderManagePanel();
			main.add(orderManagePanel,"orderManagePanel");
			main_layout.show(main, "orderManagePanel");
			this.setTitle("订单管理--订单处理");
			Util.setButtonStatus(toolBar,orderManageButton);
			SwingUtilities.invokeLater(orderManagePanel);
		}else if(e.getSource()==orderRefundButton){
			//退款单处理按钮
			orderRefundPanel = new OrderRefundPanel();
			main.add(orderRefundPanel,"orderRefundPanel");
			main_layout.show(main, "orderRefundPanel");
			this.setTitle("订单管理--退款处理");
			Util.setButtonStatus(toolBar,orderRefundButton);
			SwingUtilities.invokeLater(orderRefundPanel);
		}
		main.updateUI();
	}
	public void showButton(){
		if (toolBar != null && toolBar.getComponentCount() != 0)
			((JButton)toolBar.getComponent(0)).doClick();
	}
	
	public void showButton(int type) {
		switch(type){
		case 1:{memberConsumptionButton.doClick();break;}
		case 2:{orderOnlineButton.doClick();break;}
		case 3:{orderScheduledButton.doClick();break;}
		case 4:{orderCommentsButton.doClick();break;}
		case 5:{marketButton.doClick();break;}	
		case 6:{orderManageButton.doClick();break;}
		case 7:{orderRefundButton.doClick();break;}
	}
	}
}
